Protect against stupid bsearch() implementations. (#159737, Morten
authorMatthias Clasen <mclasen@redhat.com>
Mon, 29 Nov 2004 15:39:39 +0000 (15:39 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 29 Nov 2004 15:39:39 +0000 (15:39 +0000)
2004-11-29  Matthias Clasen  <mclasen@redhat.com>

* xdgmimeparent.c (_xdg_mime_parent_list_lookup):
* xdgmimealias.c (_xdg_mime_alias_list_lookup): Protect
against stupid bsearch() implementations.  (#159737,
Morten Welinder)

gtk/xdgmime/ChangeLog
gtk/xdgmime/xdgmimealias.c
gtk/xdgmime/xdgmimeparent.c

index 3045b7278acde47bb529abc73ff810b8bc8e488f..43a9abe10f25274e9ba7f06738acce1d4398d702 100644 (file)
@@ -1,3 +1,10 @@
+2004-11-29  Matthias Clasen  <mclasen@redhat.com>
+
+       * xdgmimeparent.c (_xdg_mime_parent_list_lookup): 
+       * xdgmimealias.c (_xdg_mime_alias_list_lookup): Protect 
+       against stupid bsearch() implementations.  (#159737,
+       Morten Welinder)
 2004-11-24  Matthias Clasen  <mclasen@redhat.com>
 
        * xdgmimeparent.c (_xdg_mime_parent_read_from_file): 
index 70ed13a4248e74ad60f48c857931a17057d47be6..2be3d3711c8d0cdfa837e884eb8c9d8ee277ba23 100644 (file)
@@ -99,13 +99,16 @@ _xdg_mime_alias_list_lookup (XdgAliasList *list,
   XdgAlias *entry;
   XdgAlias key;
 
-  key.alias = (char *)alias;
-  key.mime_type = 0;
-
-  entry = bsearch (&key, list->aliases, list->n_aliases,
-                  sizeof (XdgAlias), alias_entry_cmp);
-  if (entry)
-    return entry->mime_type;
+  if (list->n_aliases > 0)
+    {
+      key.alias = (char *)alias;
+      key.mime_type = 0;
+      
+      entry = bsearch (&key, list->aliases, list->n_aliases,
+                      sizeof (XdgAlias), alias_entry_cmp);
+      if (entry)
+       return entry->mime_type;
+    }
 
   return NULL;
 }
index 9553b4b36764a539abe62c3f9cc1b02d5a59639f..f623fb2d1c08e9a64032f5d0daa6487ed51c4823 100644 (file)
@@ -104,13 +104,16 @@ _xdg_mime_parent_list_lookup (XdgParentList *list,
   XdgMimeParents *entry;
   XdgMimeParents key;
 
-  key.mime = (char *)mime;
-  key.parents = NULL;
-
-  entry = bsearch (&key, list->parents, list->n_mimes,
-                  sizeof (XdgMimeParents), &parent_entry_cmp);
-  if (entry)
-    return (const char **)entry->parents;
+  if (list->n_mimes > 0)
+    {
+      key.mime = (char *)mime;
+      key.parents = NULL;
+      
+      entry = bsearch (&key, list->parents, list->n_mimes,
+                      sizeof (XdgMimeParents), &parent_entry_cmp);
+      if (entry)
+       return (const char **)entry->parents;
+    }
 
   return NULL;
 }